﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using SharedGenomics.Domain;
using SharedGenomics.Workbench.PresentationModel;
using SharedGenomics.Workbench.Tests.TestObjects;

namespace SharedGenomics.Workbench.Tests.PresentationModel
{
    [TestClass]
    public class DataColumnSchemaFactoryTests
    {
        private DataColumnSchemaFactory factory;

        [TestInitialize]
        public void Setup()
        {
            this.factory = new DataColumnSchemaFactory();
        }

        [TestMethod]
        public void ShouldAddDisplayColumns()
        {
            var schema = this.factory.GetColumnSchemaForType(typeof(TestAnalysisResult));
            Assert.AreEqual(7, schema.Count);
        }

        [TestMethod]
        public void ShouldSetColumnOrder()
        {
            var schema = this.factory.GetColumnSchemaForType(typeof(TestAnalysisResult));
            CollectionAssert.AreEqual(new[] { "SnpName", "StringProperty", "ShortFormatDouble", "LongFormatDouble", "P", "Emp1", "Emp2" }, schema.Select(c => c.PropertyName).ToArray());
        }

        [TestMethod]
        public void ShouldSetColumnHeaders()
        {
            var schema = this.factory.GetColumnSchemaForType(typeof(TestAnalysisResult));
            CollectionAssert.AreEqual(new[] { "SNP", "String", "Short", "Long", "P", "Emp1", "Emp2" }, schema.Select(c => c.HeaderText).ToArray());
        }

        [TestMethod]
        public void ShouldSetDoubleColumnFormats()
        {
            this.factory.SetColumnTypeDefaultFormat<double>("F8");
            var schema = this.factory.GetColumnSchemaForType(typeof(TestAnalysisResult));

            //get the 'Short', 'Long' and 'P' columns - the short and long columns have custom formats and P should use the default (i.e. F8)
            var shortCol = schema[2];
            var longCol = schema[3];
            var pCol = schema[4];

            Assert.AreEqual("F2", shortCol.Format);
            Assert.AreEqual("F10", longCol.Format);
            Assert.AreEqual("F8", pCol.Format);
        }

        [TestMethod]
        public void ShouldNotSetColumnFormat()
        {
            var schema = this.factory.GetColumnSchemaForType(typeof(TestAnalysisResult));

            //there is no default format and none is specified on the property so it should be null
            var stringCol = schema[1];
            Assert.IsNull(stringCol.Format);
        }
    }
}
